package com.liugui.thread;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @ClassName: LockDemo
 * @Author: liugui
 * @Date: 2020-11-09 10:30
 **/
public class LockDemo {
    private static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        Thread thread1 = new Thread(()->{
            lock.lock();
            try {
                System.out.println("线程1加锁");
            }finally {
                lock.unlock();
                System.out.println("线程1解锁");
            }
        });

        thread1.start();
        Thread thread2 = new Thread(()->{
            lock.lock();
            try {
                System.out.println("线程2加锁");
            }finally {
                lock.unlock();
                System.out.println("线程2解锁");
            }
        });
        thread2.start();
    }
}
